package com.telecom.hz.sample.service;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class CustomUserDetailsService implements UserDetailsService {
	
	@Autowired
	private BCryptPasswordEncoder encoder;

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		// TODO Auto-generated method stub
		String password = encoder.encode("12121122");
		String[] roles = {"USER", "ADMIN", "REMOTE"};
		ArrayList<SimpleGrantedAuthority> roleLst = new ArrayList<>(roles.length);
		for (String role : roles) {
			roleLst.add(new SimpleGrantedAuthority(role));
		}
		return new User(username, password, roleLst);
	}
}
